#include"stdio.h"
#define dataType int
#define maxLenth 100

typedef struct seqList
{
	dataType data[maxLenth];
	int listLen;
}seqList;

void  initList(seqList *L)
{
	L->listLen=0; 
}

int getListLenth(seqList *L)
{
	return L->listLen;
}

int getElement(seqList *L,int i,dataType *element)
{
	if(i>L->listLen&&i<0)
	{
		printf("index is beyond border");
        return -1;
	}
	else
	{
        *element = L->data[i];
		return 0;	
	}
}

int listLocate(seqList *L,dataType element)
{
    int i =0;
    for(i=0;i<L->listLen;i++)
    {
        if(element == L->data[i])
        {
            return i;
        }
    }

    return -1;
}

int listInsert(seqList *L,int index,dataType x)
{
    int i;
    if(L->listLen == maxLenth)
    {
        printf("overflow\n");
        return -1;
    }
    else if(index<0 || index > L->listLen)
    {
        printf("position error\n");
        return -1;
    }
    else
    {
        for ( i = L->listLen; i > index; i--)
        {
            L->data[i] = L->data[i-1];
        }
        L->data[index] = x;
        L->listLen++; 
    }
    return 0;
}

int listDelete(seqList *L,int index)
{
    int i;
    if(L->listLen == 0)
    {
        printf("L is void\n");
        return -1;
    }
    else if(index >= L->listLen||index<0)
    {
        printf("index overflow\n");
        return -1;
    }
    else
    {
        for ( i = index; i < L->listLen-1; i++)
        {
            L->data[i] = L->data[i+1];
        }
        L->listLen--;
        return 0;
    }
}

int showData(seqList *L,int index)
{
    if(index>=0&&index<L->listLen)
    {
        printf("\t %d ",L->data[index]);
        return 0;
    }
    printf("show error\n");
    return -1;
}

int main() //test
{
    seqList L;
    int i;
    initList(&L);
    for(i=0;i<101;i++)
    {
        if(listInsert(&L,i,i) == 0){showData(&L,i);}
    }
    for(i=100;i>0;i--)
    {
        if(listDelete(&L,i) == 0){showData(&L,i-1);}
    }
}